<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Edit Tournament</title>
    </h:head>
    <h:body>
        <ui:include src="../header.xhtml"/>
        <hr/>
        <f:view>
            <h:panelGrid columns="6" border="0">
                <h:form>
                    <h:panelGrid columns="3" title="Tournament">
                        <f:facet name="header">
                            <h:outputText value="Tournament"/>
                        </f:facet>
                        <h:outputLabel value="Name" for="name"/>
                        <h:inputText id="name" value="#{tournamentManagedBean.current.name}" required="true" requiredMessage="*"/>
                        <h:message for="name" style="color:red"/>

                        <h:outputLabel value="Type" for="type"/>
                        <h:selectOneMenu id="type" value="#{tournamentManagedBean.current.type}">
                            <f:selectItems value="#{tournamentManagedBean.tournamentTypes}"/>
                        </h:selectOneMenu>
                        <h:message for="type" style="color:red"/>

                        <h:outputLabel value="Start Date" for="startDate"/>
                        <h:inputText id="startDate" value="#{tournamentManagedBean.current.startDate}" required="true" requiredMessage="*">
                            <f:convertDateTime pattern="yyyy-MM-dd" type="date"/>
                        </h:inputText>
                        <h:message for="startDate" style="color:red"/>

                        <h:outputLabel value="End Date" for="endDate"/>
                        <h:inputText id="endDate" value="#{tournamentManagedBean.current.endDate}" required="true" requiredMessage="*">
                            <f:convertDateTime pattern="yyyy-MM-dd" type="date"/>
                        </h:inputText>
                        <h:message for="endDate" style="color:red"/>

                        <h:outputLabel value="Prize" for="prize"/>
                        <h:inputText id="prize" value="#{tournamentManagedBean.current.prize}" required="true" requiredMessage="*"/>
                        <h:message for="prize" style="color:red"/>

                        <h:outputLabel value="Report" for="report"/>
                        <h:inputTextarea id="report" value="#{tournamentManagedBean.current.report}"/>
                        <h:message for="report" style="color:red"/>

                        <h:commandButton value="Save" action="#{tournamentManagedBean.editTournament}"/>
                        <h:commandButton type="reset" value="Reset"/>
                    </h:panelGrid>
                </h:form>
                <h:panelGrid>
                    <h:form>
                        <h:dataTable value="#{tournamentManagedBean.current.referees}" var="item"  rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Referees"/>
                                </f:facet>
                                <h:outputText value="#{item}"/>
                            </h:column>
                            <h:column>
                                <h:commandLink value="Remove" action="#{tournamentManagedBean.removeReferee(item)}"/>
                            </h:column>
                        </h:dataTable>
                    </h:form>
                    <h:form>
                        <h:dataTable value="#{tournamentManagedBean.otherReferees}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Other Referees"/>
                                </f:facet>
                                <h:outputText value="#{item}"/>
                            </h:column>
                            <h:column>
                                <h:commandLink value="Add" action="#{tournamentManagedBean.addReferee(item)}"/>
                            </h:column>
                        </h:dataTable>
                    </h:form>

                </h:panelGrid>
                <h:panelGrid>
                    <h:form>
                        <h:dataTable value="#{tournamentManagedBean.current.umpires}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Umpires"/>
                                </f:facet>
                                <h:outputText value="#{item}"/>
                            </h:column>
                            <h:column>
                                <h:commandLink value="Remove" action="#{tournamentManagedBean.removeUmpire(item)}"/>
                            </h:column>
                        </h:dataTable>
                    </h:form>
                    <h:form>
                        <h:dataTable value="#{tournamentManagedBean.otherUmpires}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Other Umpires"/>
                                </f:facet>
                                <h:outputText value="#{item}"/>
                            </h:column>
                            <h:column>
                                <h:commandLink value="Add" action="#{tournamentManagedBean.addUmpire(item)}"/>
                            </h:column>
                        </h:dataTable>
                    </h:form>
                </h:panelGrid>
                <h:panelGrid>
                    <h:form>
                        <h:dataTable value="#{tournamentManagedBean.current.courts}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Courts"/>
                                </f:facet>
                                <h:outputText value="#{item}"/>
                            </h:column>
                            <h:column>
                                <h:commandLink value="Remove" action="#{tournamentManagedBean.removeCourt(item)}"/>
                            </h:column>
                        </h:dataTable>
                    </h:form>
                    <h:form>
                        <h:dataTable value="#{tournamentManagedBean.otherCourts}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Other Courts"/>
                                </f:facet>
                                <h:outputText value="#{item}"/>
                            </h:column>
                            <h:column>
                                <h:commandLink value="Add" action="#{tournamentManagedBean.addCourt(item)}"/>
                            </h:column>
                        </h:dataTable>
                    </h:form>
                </h:panelGrid>
                <h:form>
                    <h:dataTable value="#{tournamentManagedBean.teams}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                        <f:facet name="header">
                            <h:outputText value="Teams"/>
                        </f:facet>
                        <h:column>
                            <h:commandLink value="#{item}" action="#{teamManagedBean.linkTeam(item)}"/>
                        </h:column>
                        <h:column>
                            <h:commandLink value="Remove" action="#{tournamentManagedBean.removeTeam(item)}"/>
                        </h:column>
                    </h:dataTable>
                </h:form>
                <h:form>
                    <h:dataTable value="#{tournamentManagedBean.draw}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                        <f:facet name="header">
                            <h:outputText value="Draw"/>
                        </f:facet>
                        <h:column>
                            <h:commandLink value="#{item}" action="#{drawManagedBean.linkDraw(item,tournamentManagedBean.current)}"/>
                        </h:column>
                    </h:dataTable>
                    <h:commandButton value="Generate" action="#{tournamentManagedBean.generateDraws}"/>
                </h:form>


            </h:panelGrid>

            <hr/>
            <h:panelGrid>
                <h:form>
                    <h:dataTable value="#{tournamentManagedBean.current.matches}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                        <f:facet name="header">
                            <h:outputText value="Matches"/>
                        </f:facet>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="HomeTeam"/>
                            </f:facet>
                            <h:outputText value="#{item.homeTeam}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="AwayTeam"/>
                            </f:facet>
                            <h:outputText value="#{item.awayTeam}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Court"/>
                            </f:facet>
                            <h:outputText value="#{item.court}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Date"/>
                            </f:facet>
                            <h:outputText value="#{item.mDate}">
                                <f:convertDateTime pattern="yyyy-MM-dd" />
                            </h:outputText>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Time"/>
                            </f:facet>
                            <h:outputText value="#{item.mTime}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Score"/>
                            </f:facet>
                            <h:outputText value="#{item.score}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Report"/>
                            </f:facet>
                            <h:outputText value="#{item.report}"/>
                        </h:column>
                        <h:column>
                            <h:commandLink value="Details" action="#{mainPageManagedBean.matchDetails(item)}"/>
                        </h:column>
                        <h:column>
                            <h:commandLink value="Edit" action="#{matchManagedBean.linkMatch(item,tournamentManagedBean.current)}"/>
                        </h:column>
                        <h:column>
                            <h:commandLink value="Remove" action="#{tournamentManagedBean.removeMatch(item)}"/>
                        </h:column>
                    </h:dataTable>
                </h:form>
            </h:panelGrid>
        </f:view>
    </h:body>
</html>

